//
//  TJAcount.m
//  TJSinaWeiBo_OC
//
//  Created by 唐后能 on 16/4/19.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "TJAcount.h"

@implementation TJAcount

// 提供创建对象的方法.
-(instancetype)initWithDict:(NSDictionary*)dict {

    if (self=[super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}

+(instancetype)acountWithDict:(NSDictionary*)dict {

    return [[self alloc] initWithDict:dict];
}

// 重写expires_in的setter方法,给dueDate赋值.
- (void)setExpires_in:(NSString *)expires_in {

    _expires_in = expires_in;
    self.dueDate = [NSDate dateWithTimeIntervalSinceNow:expires_in.doubleValue];
}

// 实现归档方法.
- (void)encodeWithCoder:(NSCoder *)aCoder {
    
    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.expires_in forKey:@"expires_in"];
    [aCoder encodeObject:self.dueDate forKey:@"dueDate"];
}
// 实现解挡方法.
-(instancetype)initWithCoder:(NSCoder *)aDecoder {

    if (self=[super init]) {
        self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
        self.expires_in = [aDecoder decodeObjectForKey:@"expires_in"];
        self.dueDate = [aDecoder decodeObjectForKey:@"dueDate"];
    }
    return self;
}

@end
